import Vue from 'vue'
import Router from 'vue-router'
import store from '../utils/store'
import * as share from '../utils/share'
import Auth from '@/components/Auth'
import HelloWorld from '@/components/HelloWorld'
import Home from '@/components/Home'
import Mine from '@/components/Mine'
import School from '@/components/School'
import Course from '@/components/Course'
import Book from '@/components/Book'
import BookDetail from '@/components/BookDetail'
import Article from '@/components/Article'
import CourseDetail from '@/components/CourseDetail'
import ConfirmOrder from '@/components/ConfirmOrder'
import MyAddress from '@/components/MyAddress'
import EditAddress from '@/components/EditAddress'
import Teacher from '@/components/Teacher'
import TeacherDetail from '@/components/TeacherDetail'
import MyInfo from '@/components/MyInfo'
import Account from '@/components/Account'
import GeneralizationCode from '@/components/GeneralizationCode'
import Binding from '@/components/Binding'
import BindWx from '@/components/BindWx'
import SetPassword from '@/components/SetPassword'
import MyCourse from '@/components/MyCourse'
import MyTeam from '@/components/MyTeam'
import MyCollection from '@/components/MyCollection'
import MyWallet from '@/components/MyWallet'
import News from '@/components/News'
import NewsDetail from '@/components/NewsDetail'
import Feedback from '@/components/Feedback'
import Service from '@/components/Service'
import ArticleDetail from '@/components/ArticleDetail'
import MyCourseDetail from '@/components/MyCourseDetail'
import LearnSource from '@/components/LearnSource'
import SourceDetail from '@/components/SourceDetail'
import LearnFree from '@/components/LearnFree'
import JiaoCai from '@/components/JiaoCai'
import Contact from '@/components/Contact'
import Pinpai from '@/components/Pinpai'
import JiaoCaiList from '@/components/JiaoCaiList'
import Order from '@/components/Order'
import ContentList from '@/components/contentList'
import MyJiaocai from '@/components/myjiaocai'
import MyJiaocaiDetail from '@/components/myjiaocaidetail'
import jiaocaicontent from '@/components/jiaocaicontent'
import Course_info from '@/components/Course_info'
import About from '@/components/about'
Vue.use(Router)
const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      component: Home
    },
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/auth',
      component: Auth,
      meta: {
        requireAuth: false
      }
    },
    {
      path: '/home',
      component: Home
    },
    {
      path: '/mine',
      component: Mine
    },
    {
      path: '/course',
      component: Course,
      meta: {
        share: true
      }
    },
    {
      path: '/school',
      component: School
    },
    {
      path: '/course',
      component: Course
    },
    {
      path: '/book',
      component: Book
    },
    {
      path: '/bookdetail',
      component: BookDetail
    },
    {
      path: '/article',
      component: Article
    },
    {
      path: '/teacher',
      component: Teacher
    },
    {
      path: '/coursedetail',
      component: CourseDetail
    },
    {
      path: '/confirmorder',
      component: ConfirmOrder
    },
    {
      path: '/myaddress',
      component: MyAddress
    },
    {
      path: '/editaddress',
      component: EditAddress
    },
    {
      path: '/teacherdetail',
      component: TeacherDetail
    },
    {
      path: '/myinfo',
      component: MyInfo
    },
    {
      path: '/account',
      component: Account
    },
    {
      path: '/generalizationcode',
      component: GeneralizationCode
    },
    {
      path: '/binding',
      component: Binding
    },
    {
      path: '/BindWx',
      component: BindWx
    },
    {
      path: '/setpassword',
      component: SetPassword
    },
    {
      path: '/mycourse',
      component: MyCourse
    },
    {
      path: '/myteam',
      component: MyTeam
    },
    {
      path: '/mycollection',
      component: MyCollection
    },
    {
      path: '/mywallet',
      component: MyWallet
    },
    {
      path: '/news',
      component: News
    },
    {
      path: '/newsdetail',
      component: NewsDetail
    },
    {
      path: '/feedback',
      component: Feedback
    },
    {
      path: '/service',
      component: Service
    },
    {
      path: '/articledetail',
      component: ArticleDetail
    },
    {
      path: '/mycoursedetail',
      component: MyCourseDetail
    },
    {
      path: '/learnsource',
      component: LearnSource
    },
    {
      path: '/sourcedetail',
      component: SourceDetail
    },
    {
      path: '/learnfree',
      component: LearnFree
    },
    {
      path: '/jiaocai',
      component: JiaoCai
    },
    {
      path: '/contact',
      component: Contact
    },
    {
      path: '/pinpai',
      component: Pinpai
    },
    {
      path: '/jiaocailist',
      component: JiaoCaiList
    },
    {
      path: '/order',
      component: Order
    },
    {
      path: '/contentlist',
      component: ContentList
    },
    {
      path: '/myjiaocai',
      component: MyJiaocai
    },
    {
      path: '/myjiaocaidetail',
      component: MyJiaocaiDetail
    },
    {
      path: '/jiaocaicontent',
      component: jiaocaicontent
    },
    {
      path: '/Course_info',
      component: Course_info,
      meta: {
        share: true
      }
    },
    {
      path: '/about',
      component: About
    },
  ]
})

router.beforeEach((to, from, next) => {
  // 分销
  if (to.query.referId) {
    store.commit('setReferId', to.query.referId)
  }
  if (store.getters.token == '' && to.meta.requireAuth !== false) {
    next({
      path: '/auth'
    })
  } else if (to.meta.share) {
    share.wxShareAppMessage()
    share.wxShareTimeline()
    next()
  } else {
    next()
  }
})

export default router
